#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <assert.h>
#include <stdarg.h>
#include <errno.h>
#include <share.h>

typedef struct node
{
    int data;

    struct node* prev;
    struct node* next;
}node_t;

int main(int argc, char* argv[])
{
    node_t* head = (node_t*)malloc(sizeof(node_t));
    assert(head);
    head->data = -1;
    head->prev = head;
    head->next = head;

    while (1)
    {
        printf("please put a data: ");
        int data = 0;
        scanf("%d", &data);
        getchar();

        if (data == -1)
        {
            break;

        }

        node_t* new = (node_t*)malloc(sizeof(node_t));
        new->data = data;
        new->next = NULL;
        new->prev = NULL;

        node_t* tmp = head->next;

        while (new->data > tmp->data && tmp != head)
        {
            tmp = tmp->next;
        }

        node_t* tmpprev = tmp->prev;
        tmpprev->next = new;
        new->next = tmp;
        tmp->prev = new;
        new->prev = tmpprev;

    }
    node_t* tmp = head->next;
    while (tmp != head)
    {
        printf("%d ", tmp->data);
        tmp = tmp->next;
    }

    putchar(10);
    return 0;
}
